﻿using Application.Features.Tenants.DTOs;
using Application.Features.Tenants.Queries.GetAll;
using Common.Models;
using Domain.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;

namespace WebAPI.Controllers;

/// <summary>
/// 多租户管理
/// </summary>
[Description("多租户管理")]
public class MultiTenancyController : ApiControllerBase
{
    private readonly MultiTenancyService _multiTenancyService;

    public MultiTenancyController(MultiTenancyService multiTenancyService)
    {
        _multiTenancyService = multiTenancyService;
    }

    /// <summary>
    /// 全部查询
    /// </summary>
    /// <returns></returns>
    [HttpGet("query/all")]
    [AllowAnonymous]
    [Description("全部查询")]
    public async Task<Result<IEnumerable<TenantOptionOutput>>> GetAllTenantsAsync()
    {
        var data = await Mediator.Send(new GetAllTenantsQuery() { });
        return await Result<IEnumerable<TenantOptionOutput>>.SucceedAsync(data);
    }

    /// <summary>
    /// 是否开启
    /// </summary>
    /// <returns></returns>
    [HttpGet("is/enabled")]
    [AllowAnonymous]
    [Description("是否开启")]
    public Result<bool> IsEnabledMultiTenancy()
    {
        return Result<bool>.Succeed(_multiTenancyService.IsEnabled());
    }
}
